﻿using Net5ApiANdWpfClient.Lib.Common;
using Net5ApiANdWpfClient.Lib.Model;
using Net5ApiANdWpfClient.Lib.Model.SystemAdmin;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Net5ApiANdWpfClient.Lib.Service
{
    public class RoleService
    {
        /// <summary>
        /// 角色搜索方法
        /// </summary>
        /// <param name="loginName">角色名称</param>
        /// <param name="CurrentPageIndex">当前页</param>
        /// <returns></returns>
        public PagerResult<RoleView> SearchPage(string roleName, int CurrentPageIndex)
        {
            string apiUrl = "SystemAdmin/RoleManager/SearchPage"; //请求api的路径
            SearchModel search = new SearchModel()
            {
                SearchItem = new Dictionary<string, string> { { "role_name", roleName } } ,
                page = CurrentPageIndex,
                limit = PcConfig.PageSize
            };
            ResultModel result = HttpRequestTools.PostByToken(apiUrl, JsonConvert.SerializeObject(search));
            if (result.code == ResultCode.Ok)
            {
                return JsonConvert.DeserializeObject<PagerResult<RoleView>>(JsonConvert.SerializeObject(result.data));
            }
            else
            {
                return null;
            }

        }
    }
}
